$(document).ready(function() {
	show();
	$( "#showAG" ).click(function() {
		var PeNo = $("#peno").val();
		var YyMm = $("#yymm").val();
	//	alert(PeNo+"   "+YyMm);
		$.ajax({
			url : 'ACM11022Srvl', 
			type : "get",
			data : {
				process_type:"showAG",
				peNo: PeNo,
				monthYear:YyMm
			},
			dataType : "json",
			success: function(data){
				var message = "";
				message +="<table class='table-list table-bordered table-hover'>";
				message +=" <thead>";
				message +=" <tr>";
				message +=" <th>เดือน/ปี</th>";
				message +=" <th>รหัสตัวแทน</th>";  
				message +=" <th>รหัสกรมธรรม์</th>";  
				message +=" <th>ประเภทกรมธรรม์</th>";  
				message +=" <th>จำนวนกรมธรรม์</th>";  
				message +=" </tr>";
				message +=" </thead>";   
				message +=" <tbody>";  
				
				for (var i = 0; i < parseInt(data.PeNo.length) ; i++) {
				message +=" <tr>";
				message +=" <td>"+data.closym[i]+"</td>";
				message +=" <td>"+data.PeNo[i]+"</td>";
				message +=" <td>"+data.pono[i]+"</td>";
				message +=" <td>"+data.payment[i]+"</td>";
				message +=" <td>"+data.amount[i]+"</td>";
				message +=" </tr>";
				}
				message +=" </tbody>";   
				message +=" </table>";   
				
				document.getElementById("showdetailsAG").innerHTML= message;
				$("#detailsModal").modal('show');
			}
			
		});
	});	
});

function show(){
	var PeNo = $("#peno").val();
	var YyMm = $("#yymm").val();
	$.ajax({
		url : 'ACM11022Srvl', 
		type : "get",
		data : {
			peNo: PeNo,
			monthYear:YyMm
		},
		dataType : "json",
		success: function(data){
			var message = "";
			message +="<table class='table-list table-bordered table-hover'>";
			message +=" <thead>";
			message +=" <tr>";
			message +=" <th>PE_NO_COL</th>"; 
			message +=" <th>PO_NO</th>";
			message +=" <th>Rider CD</th>";  
			message +=" <th>Total FreeLook</th>";  
			message +=" <th>Issue Date</th>";  
			message +=" </tr>";
			message +=" </thead>";   
			message +=" <tbody>";  
			
			for (var i = 0; i < parseInt(data.PeNo.length) ; i++) {
			message +=" <tr>";
			message +=" <td>"+data.PeNo[i]+"</td>";
			message +=" <td>"+data.PoNo[i]+"</td>";
			message +=" <td>"+data.rider[i]+"</td>";
			message +=" <td style='text-align: right;'>"+data.total[i]+"</td>";
			message +=" <td>"+data.issue[i]+"</td>";
			message +=" </tr>";
			}
			message +=" </tbody>";   
			message +=" </table>";   
			
			$("#table-negative").html(message);
		}
		
	});
}


